package com.srxz.mobilepharmacy.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.io.Serializable;
import java.math.BigInteger;

@Embeddable
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ClinicRecPK implements Serializable {
    @Column(name = "aid")
    private BigInteger aid;
    @Column(name = "patid")
    private BigInteger patid;
    @Column(name = "sn")
    private BigInteger sn;
    @Column(name = "ord")
    private Integer ord;
    @Column(name = "auid")
    private BigInteger auid;

    //TODO 重写hashCode、equals 保证对象比较相等

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (aid == null ? 0 : aid.hashCode());
        result = prime * result + (patid == null ? 0 : patid.hashCode());
        result = prime * result + (sn == null ? 0 : sn.hashCode());
        result = prime * result + (ord == null ? 0 : ord.hashCode());
        result = prime * result + (auid == null ? 0 : auid.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if(this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        ClinicRecPK other = (ClinicRecPK) obj;
        if (aid == null) {
            if (other.aid != null)
                return false;
        } else if (!aid.equals(other.aid))
            return false;

        if (patid == null) {
            if (other.patid != null)
                return false;
        } else if (!patid.equals(other.patid))
            return false;

        if (sn == null) {
            if (other.sn != null)
                return false;
        } else if (!sn.equals(other.sn))
            return false;

        if (ord == null) {
            if (other.ord != null)
                return false;
        } else if (!ord.equals(other.ord))
            return false;

        if (auid == null) {
            if (other.auid != null)
                return false;
        } else if (!auid.equals(other.auid))
            return false;

        return true;
    }
}
